// import * as Cesium from 'cesium';
import * as DCesium from 'cesium';
import { IComponent, AComponent } from '../../core/component';
declare const Cesium: any;
interface IViewer {
    new (...args: any): DCesium.Viewer;
}
const Viewer: IViewer = Cesium.Viewer;
// 106.677783,29.496407
export class Start implements IComponent{
    constructor(container: HTMLElement, private id: string) {
        
    }
    public init() {
        // let viewer = new Viewer(this.id, {
        //     scene3DOnly: true,  
        //     selectionIndicator: false,  
        //     baseLayerPicker: false  
        // });
        // console.log(viewer);
        // viewer.camera.flyTo({
        //     // destination: Cesium.Cartesian3.fromDegrees(29.496407, 106.677783, 2000),
        //     destination: Cesium.Cartesian3.fromDegrees(106.677783, 29.496407, 2000),
        //     orientation: {
        //         heading: 0,                         
        //         pitch: Cesium.Math.toRadians(-70.5 || -Cesium.Math.PI_OVER_FOUR),     
        //         roll: Cesium.Math.toRadians(360 || 0)      
        //     },                        
        //     duration: 3,
        // })
        // let osm = Cesium.createOpenStreetMapImageryProvider({
        //     url: 'https://a.tile.openstreetmap.org/'
        // });
        let viewer = new Cesium.Viewer(this.id, {
            // imageryProvider: osm,
            contextOptions: {
                webgl: {
                    alpha: true
                }
            },
            selectionIndicator: false,
            animation: false,  //是否显示动画控件
            baseLayerPicker: false, //是否显示图层选择控件
            geocoder: false, //是否显示地名查找控件
            timeline: false, //是否显示时间线控件
            sceneModePicker: false, //是否显示投影方式控件
            navigationHelpButton: false, //是否显示帮助信息控件
            infoBox: false,  //是否显示点击要素之后显示的信息
            fullscreenButton: false,
            shouldAnimate : true //动画播放
        });
        //取消双击事件
        //viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
        //设置homebutton的位置
        Cesium.Camera.DEFAULT_VIEW_RECTANGLE =
            Cesium.Rectangle.fromDegrees(110.15, 34.54, 110.25, 34.56);//Rectangle(west, south, east, north)
        //设置初始位置
        viewer.camera.setView({
            destination: Cesium.Cartesian3.fromDegrees(110.20, 34.55, 3000000)
        });

        //开启深度检测
        //viewer.scene.globe.depthTestAgainstTerrain = true;

        viewer.extend(Cesium.viewerCesiumInspectorMixin);//辅助工具

        //.glb  二进制GLTF格式
        let modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
            Cesium.Cartesian3.fromDegrees(104, 30, 0.0));

        viewer.scene.primitives.add(Cesium.Model.fromGltf({
            url: '/assets//SampleData/models/GroundVehicle/GroundVehicle.glb',
            modelMatrix: modelMatrix,
            scale: 10000.0
        }));
        viewer.camera.flyTo({//设置视角  
            destination: Cesium.Cartesian3.fromDegrees(104, 30, 100000.0)
        });


        //飞机
        let fly = viewer.entities.add({
            name: "飞机",
            position: Cesium.Cartesian3.fromDegrees(104, 30, 100000),
            orientation: Cesium.Transforms.headingPitchRollQuaternion(Cesium.Cartesian3.fromDegrees(104, 30, 300000), new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(0), 0, 0)),//和飞行姿态相关
            model: {
                uri: "/assets//SampleData/models/CesiumAir/Cesium_Air.glb",
                minimumPixelSize: 128,
                maximumScale: 20000
            }
        });
        console.log(fly)
        //行走的人
        viewer.entities.add({
            name: "行走的人",
            position: Cesium.Cartesian3.fromDegrees(104, 31, 0),
            orientation: Cesium.Transforms.headingPitchRollQuaternion(Cesium.Cartesian3.fromDegrees(104, 31, 0), new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(0), 0, 0)),
            model: {
                uri: "/assets//SampleData/models/CesiumMan/Cesium_Man.glb",
                minimumPixelSize: 128,
                maximumScale: 100000
            }
        });
    }
    public render(): HTMLElement {
        return null;
    }
}
